<template>
    <div>
        <div style="padding: 10px 0">
            <center><h1 class="block-top">可视化数据分析</h1></center>
            <br>
            <br>
        </div>

        <el-row >
            <el-col :span="12" :offset="4">
                <div id="main" style="width: 1000px;height: 500px;"></div>
            </el-col>

        </el-row>
        <el-divider></el-divider>
        <el-row>
            <el-col :span="12">
                <div id="mm" style="width: 500px;height: 400px"></div>
            </el-col>
            <el-col :span="12">
                <div id="pie" style="width: 500px;height: 400px"></div>
            </el-col>
        </el-row>
    </div>
</template>
<script>
    import * as echarts from 'echarts';

    export default {
        name:"Data",
        data(){
            return{

            }
        },
        mounted() {
            // 页面元素渲染之后触发
            var option;
                option = {
                    title: {
                        text: '各季度帖子发布量',
                        subtext: '趋势图',
                        left: 'center'
                    },
                xAxis: {
                    type: 'category',
                    data: ["第一季度", "第二季度", "第三季度", "第四季度"]
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: [],
                        type: 'line'
                    },
                    {
                        data: [],
                        type: 'bar'
                    }
                ]
            };
            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);
            this.request.get("/echarts/posttime").then(res=>{
                option.series[0].data=res.data
                option.series[1].data=res.data
                myChart.setOption(option);
            })


            // 饼图
            var pieoption;
            pieoption = {
                title: {
                    text: '注册用户性别比例',
                    subtext: '比例图',
                    left: 'center'
                },
                tooltip: {
                    trigger: 'item'
                },
                legend: {
                    orient: 'vertical',
                    left: 'left'
                },
                series: [
                    {
                        name: 'Access From',
                        type: 'pie',
                        radius: '60%',
                        label:{
                            type:'pie',
                            position:'inner',
                            textStyle(){
                                fontWeight:300;
                                fontSize:26
                            },
                            formatter:'{d}%'
                        },
                        data: [],
                        emphasis: {
                            itemStyle: {
                                shadowBlur: 10,
                                shadowOffsetX: 0,
                                shadowColor: 'rgba(0,0,0,0.5)'
                            }
                        }
                    }
                ]
            };
            var pieDom = document.getElementById('pie');
            var pieChart = echarts.init(pieDom);
            this.request.get("/echarts/genderre").then(res=>{
                pieoption.series[0].data=[
                    {name:"男", value : res.data[0]},
                    {name:"女", value : res.data[1]},
                ]
                pieChart.setOption(pieoption);
            })

            // 玫瑰图
            var mmoption;
            mmoption = {
                    legend: {
                        top: 'bottom'
                    },
                title: {
                    text: '用户状态',
                    subtext: '玫瑰图',
                    left: 'center'
                },
                series: [
                    {
                        name: 'Nightingale Chart',
                        type: 'pie',
                        radius: [50, 140],
                        center: ['50%', '50%'],
                        roseType: 'area',
                        itemStyle: {
                            borderRadius: 8
                        },
                        data: []
                    }
                ]
            };
            var mmchartDom = document.getElementById('mm');
            var mmChart = echarts.init(mmchartDom);
            this.request.get("/echarts/statusre").then(res=>{
                mmoption.series[0].data=[
                    { value: res.data[0], name: '正常' },
                    { value: res.data[1], name: '禁用' },
                    { value: res.data[2], name: '注销' },
                    { value: res.data[3], name: '首次注册' },
                ]
                mmChart.setOption(mmoption);
            })

        }
    }
</script>
<style>

</style>